<?php
namespace app\shop\home;

use app\shop\model\Address;
use app\shop\model\Banner;
use app\shop\model\Artwork;
use app\shop\model\Like as LikeModel;
use app\shop\model\User;
use think\Cache;
use app\admin\model\Attachment;
/**
 * 个人中心
 */
class Like extends Common
{

	public function _initialize()
	{
		parent::_initialize();
		$userInfo = User::where('id',session("auction_user")['id'])->find();
		if(isset($userInfo->money) && !$userInfo->money){
            $userInfo->money = '0.00';
        }
		$this->assign('userInfo', $userInfo);
	}

	public function index()
	{   
        $likeInfo = LikeModel::where('status',1)->order('sort asc')->column('id,type,title');
        $userLike = User::where('id',session("auction_user")['id'])->field('like,like_text')->find();
        $kile = $userLike['like'] ?explode(',', $userLike['like']):[];
        $likeText = $userLike['like_text'];
        $type = [
            1=>'按照媒介',
            2=>'按照品类',
            3=>'按照题材',
            4=>'按照风格/运动',
        ];
        $this->assign('type', $type);
        $this->assign('like', $kile);
        $this->assign('likeText', $likeText);
        $this->assign('likeInfo', $likeInfo);
        if(isMobile()){
            return $this->fetch('Mobile/Account/like');
        }else{
            return $this->fetch();
        }
	}

    public function ajaxLike()
    {
        $postData = request()->post();
        $data['id'] = session("auction_user")['id'];
        $data['like'] = isset($postData['like_id']) ? $postData['like_id'] : '';
        $data['like_text'] = isset($postData['like_text']) ? $postData['like_text'] : '';
        $data['update_time'] = time();
        $res = User::where('id',$data['id'])->update($data);
        if($res){
            $re['code'] = 0;
            $re['msg'] = '喜好设置成功！';
        }else{
             $re['code'] = 1;
             $re['msg'] = '喜好设置失败！';
        }
        echo json_encode($re);exit;
    }
}